package com.admin.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.admin.bean.AdminSpBean;
import com.admin.bean.AdminStatFeeBean;
import com.admin.util.SqlUtil;

@Repository
public class AdminStatFeeDao {

	@Autowired private JdbcTemplate jdbcTemplate;
	@Autowired private QueryRunner queryRunner;
	
	
	public List<AdminStatFeeBean> findStatByCondition(String condition)  throws SQLException{
		final String sql = "select dt,sum(moUser) as moUser,sum(cpMoUser) as cpMoUser, channel as cpid,gatewayid as spid,province as cityid,sum(mo) as mo,sum(mt) as mt,sum(infofee) as infofee,sum(income) as income,sum(statmt) as statmt, sum(statfee) as statfee, sum(statincome) as statincome  " +
				",sum(cpMo) as cpMo,sum(cpMt) as cpMt,sum(cpInfofee) as cpInfofee,sum(cpIncome) as cpIncome,sum(cpStatmt) as cpStatmt, sum(cpStatfee) as cpStatfee, sum(cpStatincome) as cpStatincome from T_co_stat_fee "+ condition;
		//System.out.println(sql);
		return queryRunner.query(sql, new BeanListHandler<AdminStatFeeBean>(AdminStatFeeBean.class),new Object[]{});
	}
	
	public List<AdminStatFeeBean> findHourStatByCondition(String condition)  throws SQLException{
		final String sql = "select dt,sum(moUser) as moUser,sum(cpMoUser) as cpMoUser, channel as cpid,gatewayid as spid,province as cityid,sum(mo) as mo,sum(mt) as mt,sum(infofee) as infofee,sum(income) as income,sum(statmt) as statmt, sum(statfee) as statfee, sum(statincome) as statincome  " +
		",sum(cpMo) as cpMo,sum(cpMt) as cpMt,sum(cpInfofee) as cpInfofee,sum(cpIncome) as cpIncome,sum(cpStatmt) as cpStatmt, sum(cpStatfee) as cpStatfee, sum(cpStatincome) as cpStatincome from T_co_stat_fee_detail "+ condition;
		System.out.println(sql);
		return queryRunner.query(sql, new BeanListHandler<AdminStatFeeBean>(AdminStatFeeBean.class),new Object[]{});
	}
}
